package com.yanqu.road.server.cmd.activity.snowgarden;

import com.yanqu.road.entity.activity.snowgarden.SnowGardenUserData;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SnowGardenProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.snowgarden.SnowGardenModule;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.snowgarden.SnowGardenMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = GameProtocol.S_SNOW_GARDEN_DRAW, desc = "请求冰雪游园会投掷")
public class SnowGardenDrawCmd extends AbstractCommand {
    private int times = 0;  // 投掷次数
    private int period = 0;  // 投掷阶段
    private boolean isSkip = false; // 是否跳过
    private List<Integer> number = new ArrayList<>(); // 指定点数

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SnowGardenProto.SnowGardenDrawReqMsg reqMsg = SnowGardenProto.SnowGardenDrawReqMsg.parseFrom(packet.getBytes());
        times = reqMsg.getTimes();
        period = reqMsg.getPeriod();
        isSkip = reqMsg.getIsSkip();
        number = reqMsg.getNumberList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {


        ret = player.getModule(SnowGardenModule.class).draw(period, times, isSkip, number);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            SnowGardenProto.SnowGardenDrawRespMsg.Builder builder = SnowGardenProto.SnowGardenDrawRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SNOW_GARDEN_DRAW, builder);
        }
    }
}
